package com.itheima.socket.tcp.demo06;

import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;

public class ClientDemo01 {

    public static void main(String[] args) throws Exception {

        // 1. 创建Socket对象
        Socket socket = new Socket(InetAddress.getByName("169.254.106.206") , 8080) ;

        // 2. 获取输出流对象
        OutputStream outputStream = socket.getOutputStream();

        // 3. 写数据
        outputStream.write("你好,itcast".getBytes("UTF-8"));

        // 4. 获取输入流对象
        InputStream inputStream = socket.getInputStream();

        // 5. 读取数据
        byte[] bytes = new byte[1024] ;
        int len = inputStream.read(bytes) ;
        System.out.println(new String(bytes , 0 ,  len , "UTF-8"));

        // 6. 释放资源
        socket.close();

    }

}
